#include "filewatcherthread.h"

#include <QDir>
#include <QTimer>

FileWatcherThread::FileWatcherThread(const QString &dir, QObject *parent):
    m_dir(dir),
    QThread(parent)
{

}

void FileWatcherThread::scanDir()
{
    QStringList removed, added;
    removed = m_files;
    QStringList files = QDir(m_dir).entryList(QDir::Files);
    foreach (const QString &f, files) {
        QString file = m_dir + QDir::separator() + f;
        if (m_files.contains(file)) {
            removed.removeOne(file);
        } else {
            //added += file;
        }
        added += file;
    }
    /*
    foreach (const QString &f, removed) {
        m_files.removeOne(f);
    }
    m_files += added;
    */
    m_files = added;

    emit filesChanged(removed, added);
    QTimer::singleShot(500, this, SLOT(scanDir()));
}
